package com.cat.dataStructure03;

import java.io.*;

/**
 * @author 曲大人的喵
 * @description https://www.luogu.com.cn/problem/P1890
 * @create 2025/11/18 10:00
 * @since JDK17
 */

public class Solution83 {
    static int n, m, MAXN = ((int) (1e3 + 10)), LIMIT = 10;
    static int[] arr = new int[MAXN], log2 = new int[MAXN];
    static int[][] stgcd = new int[MAXN][LIMIT];
    static int gcd(int x, int y) {
        return y == 0 ? x : gcd(y, x % y);
    }
    static int query(int l, int r) {
        int p = log2[r - l + 1];
        return gcd(stgcd[l][p], stgcd[r - (1 << p) + 1][p]);
    }
    static void build() {
        log2[0] = -1;
        for (int i = 1; i <= n; i++) {  // 第一列
            log2[i] = log2[i >> 1] + 1;
            stgcd[i][0] = arr[i];
        }
        for (int p = 1; p <= log2[n]; p++) {
            for (int i = 1; i + (1 << p) - 1 <= n; i++) {
                stgcd[i][p] = gcd(stgcd[i][p - 1], stgcd[i + (1 << p - 1)][p - 1]);
            }
        }
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StreamTokenizer in = new StreamTokenizer(br);
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        in.nextToken();
        n = ((int) in.nval);
        in.nextToken();
        m = ((int) in.nval);
        for (int i = 1; i <= n; i++) {
            in.nextToken();
            arr[i] = ((int) in.nval);
        }
        build();
        for (int i = 1, l, r; i <= m; i++) {
            in.nextToken();
            l = ((int) in.nval);
            in.nextToken();
            r = ((int) in.nval);
            out.println(query(l, r));
        }

        out.flush();
        out.close();
        br.close();
    }
}
